﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%= @product.name %></title>
<%= javascript_include_tag :defaults %>
<script language="javascript">
	// the array to store validate js
	var field_validates = new Array();
	function set_field_validate(model, field, id){
		field_validates.push(get_js(model, field, id));
	}
	
	function get_js(model, field, id){
		var js="new Ajax.Request('/"+ model +"/check_"+ field +"', {asynchronous:false, evalScripts:true, parameters:'"+ field +"=' + encodeURIComponent($('"+ id +"').value)})";
		return js;
	}
	
	function validate_form(){
		for(var i = 0; i< field_validates.length; i++){
			var js = field_validates[i];
			eval(js);
		}
		
		if($("commit").disabled){
			return false;
		}else{
			return true;
		}
	}
</script>
</head>

<body>
  <% form_tag :action => "create" do %>
    <%= hidden_field_tag :store, "1" %>
    <%= hidden_field_tag :model, @product.model %>
	<% for field in @product.fields %>
      <p>
        <label><%= field.name %></label><br/>
        <%= form_field @product, field, @store_product %>
      </p>
    <% end %>
    <%= submit_tag("Save", :id => 'commit', :onclick => "return validate_form();") %>
  <% end %>
</body>
</html>